package independence.collections
{
	import __AS3__.vec.Vector;
	
	/**
	 * The Vectors class provides a few helper methods for working with the new Flash Player 10
	 * <code>Vector</code> class, such as methods for sorting, filtering, and manipulating a 
	 * <code>Vector</code>'s contents. 
	 * 
	 * @version ActionScript 3.1 / Flash Player 10
	 * @author	TK, TK Assembled for Independence Glory.
	 */
	public final class Vectors
	{
		/**
		 * Determines whether <code>value1</code> is alphabetically greater, less than, or equal to
		 * <code.value2</code>. Use this in coordination with Vector.sort() as the sort function. 
		 * 
		 * @param	value1	The first value to compare.
		 * @param	value2	The second value to compare.
		 * @return	Returns positive 1 if <code>value1</code> is greater than <code>value2</code>, negative 1 if 
		 * 			<code>value1</code> is less than <code>value2</code>, and 0 if they are equal.
		 */
		public static function compareAlphabetical(value1:Object, value2:Object):int
		{
			if (value1 is String && value2 is String) {
				value1 = String(value1).toLowerCase();
				value2 = String(value2).toLowerCase();
			}
			
			if (value1 > value2) {
				return 1;
			} else if (value1 < value2) {
				return -1;
			} else {
				return 0;
			}
		}
		/**
		 * Determines whether <code>value1</code> is numerically greater, less than, or equal to
		 * <code.value2</code>. Use this in coordination with Vector.sort() as the sort function. 
		 * 
		 * @param	value1	The first value to compare.
		 * @param	value2	The second value to compare.
		 * @return	Returns positive 1 if <code>value1</code> is greater than <code>value2</code>, negative 1 if 
		 * 			<code>value1</code> is less than <code>value2</code>, and 0 if they are equal.
		 */
		public static function compareNumerical(value1:Object, value2:Object):int
		{
			if (value1 > value2) {
				return 1;
			} else if (value1 < value2) {
				return -1;
			} else {
				return 0;
			}
		}
		/**
		 * Determines whether or not the <code>target</code> <code>Vector</code> has the <code>value</code>
		 * object as one of its entries.
		 * @param	target	The <code>Vector</code> to search for the <code>value</code>
		 * @param	value	The <code>value</code> to search for in the <code>Vector</code>
		 * @return	Returns true if a match is found, false otherwise.
		 */
		public static function hasValue(target:Vector, value:Object):Boolean
		{
			for each(var entity:* in target) {
				if (entity == value) {
					return true;
				}
			}
			
			return false;
		}
	}
}